package com.littleant.web.controller.customer;

import com.littleant.common.annotation.Log;
import com.littleant.common.core.controller.BaseController;
import com.littleant.common.core.domain.AjaxResult;
import com.littleant.common.core.page.TableDataInfo;
import com.littleant.common.enums.BusinessType;
import com.littleant.common.utils.poi.ExcelUtil;
import com.littleant.customer.domain.CrmCustomerInfo;
import com.littleant.customer.service.ICrmCustomerInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 客户信息管理Controller
 * 
 * @author littleant
 * @date 2022-03-15
 */
@RestController
@RequestMapping("/customer/info")
public class CrmCustomerInfoController extends BaseController
{
    @Autowired
    private ICrmCustomerInfoService crmCustomerInfoService;

    /**
     * 查询客户信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('customer:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmCustomerInfo crmCustomerInfo)
    {
        startPage();
        List<CrmCustomerInfo> list = crmCustomerInfoService.selectCrmCustomerInfoList(crmCustomerInfo);
        return getDataTable(list);
    }

    /**
     * 导出客户信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('customer:info:export')")
    @Log(title = "客户信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmCustomerInfo crmCustomerInfo)
    {
        List<CrmCustomerInfo> list = crmCustomerInfoService.selectCrmCustomerInfoList(crmCustomerInfo);
        ExcelUtil<CrmCustomerInfo> util = new ExcelUtil<CrmCustomerInfo>(CrmCustomerInfo.class);
        util.exportExcel(response, list, "客户信息管理数据");
    }

    /**
     * 获取客户信息管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('customer:info:query')")
    @GetMapping(value = "/{customerId}")
    public AjaxResult getInfo(@PathVariable("customerId") Long customerId)
    {
        return AjaxResult.success(crmCustomerInfoService.selectCrmCustomerInfoByCustomerId(customerId));
    }

    /**
     * 新增客户信息管理
     */
    @PreAuthorize("@ss.hasPermi('customer:info:add')")
    @Log(title = "客户信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmCustomerInfo crmCustomerInfo)
    {
        return toAjax(crmCustomerInfoService.insertCrmCustomerInfo(crmCustomerInfo));
    }

    /**
     * 修改客户信息管理
     */
    @PreAuthorize("@ss.hasPermi('customer:info:edit')")
    @Log(title = "客户信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmCustomerInfo crmCustomerInfo)
    {
        return toAjax(crmCustomerInfoService.updateCrmCustomerInfo(crmCustomerInfo));
    }

    /**
     * 删除客户信息管理
     */
    @PreAuthorize("@ss.hasPermi('customer:info:remove')")
    @Log(title = "客户信息管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{customerIds}")
    public AjaxResult remove(@PathVariable Long[] customerIds)
    {
        return toAjax(crmCustomerInfoService.deleteCrmCustomerInfoByCustomerIds(customerIds));
    }
}
